using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using Campus.Entities;

namespace CampusSite.Models
{ 
    public class PagoRepository : IPagoRepository
    {
        CampusSiteContext context = new CampusSiteContext();

        public IQueryable<Pago> All
        {
            get { return context.Pagos; }
        }

        public IQueryable<Pago> AllIncluding(params Expression<Func<Pago, object>>[] includeProperties)
        {
            IQueryable<Pago> query = context.Pagos;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public Pago Find(int id)
        {
            return context.Pagos.Find(id);
        }

        public void InsertOrUpdate(Pago pago)
        {
            if (pago.PagoId == default(int)) {
                // New entity
                context.Pagos.Add(pago);
            } else {
                // Existing entity
                context.Entry(pago).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var pago = context.Pagos.Find(id);
            context.Pagos.Remove(pago);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose() 
        {
            context.Dispose();
        }
    }

    public interface IPagoRepository : IDisposable
    {
        IQueryable<Pago> All { get; }
        IQueryable<Pago> AllIncluding(params Expression<Func<Pago, object>>[] includeProperties);
        Pago Find(int id);
        void InsertOrUpdate(Pago pago);
        void Delete(int id);
        void Save();
    }
}